﻿using KouDai.Core.Engine;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace KouDai.Core.Service
{
    public class SuperImageService
    {
        #region Singleton

        private static SuperImageService _instance;
        public static SuperImageService Instance
        {
            get
            {
                return _instance ?? (_instance = new SuperImageService());
            }
        }
        #endregion

        public async Task<Stream> CacheImage(string imageUrl)
        {
            CommunicationData communicationData = new CommunicationData();
            SendData sendData = new SendData(imageUrl);
            BackData backData = new BackData(null);
            communicationData.SendData = sendData;
            communicationData.BackData = backData;
            communicationData.Parser = null;

            ServiceFileEngine serviceFileEngine = new ServiceFileEngine();
            await serviceFileEngine.RequestAsync(communicationData,CancellationToken.None);
            Stream fileStream = backData.ResposeData as Stream;

            return fileStream;
        }
    }
}
